package com.ysd.modules.sys.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ysd.common.utils.PageUtils;
import com.ysd.common.utils.R;
import com.ysd.modules.sys.entity.SysSchoolEntity;
import com.ysd.modules.sys.entity.SysStudent;
import com.ysd.modules.sys.service.SysClassesService;
import com.ysd.modules.sys.service.SysStudentService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@RestController
@Api(description = "PC学生管理")
@RequestMapping("/sys/student")
public class SysStudentController {
	
	@Autowired
    private SysStudentService studentService;
	
	@ApiOperation("根据学生名分页查询学生")
    @GetMapping("getAllStudents")
    public R getAllStudents(String sid,String cid, String name,Integer page, Integer limit) {
        PageUtils pageUtils = studentService.getAllStudents(sid,cid,name, page, limit);
        return R.ok().put("data", pageUtils);
    }
	
	@ApiOperation("根据id查询学生信息")
	@GetMapping("selectById")
	public R selectSchool(Integer id) {
		SysStudent data = studentService.getById(id);
		return R.ok().put("data", data);
	}

    @PostMapping("addStudents")
    @ApiOperation("添加学生")
    public R addStudents(@RequestBody SysStudent sysStudent) {
        int i = studentService.addStudents(sysStudent);
        if (i > 0) {
            return R.ok();
        } else {
            return R.error();
        }
    }

    @PostMapping("delStudents")
    @ApiOperation("根据id删除学生")
    public R delStudents(Integer id) {
        int i = studentService.delStudents(id);
        if (i > 0) {
            return R.ok();
        } else {
            return R.error();
        }
    }

    @PostMapping("updateStudents")
    @ApiOperation("修改学生")
    public R updateStudents(SysStudent c) {
        int i = studentService.updateStudents(c);
        if (i > 0) {
            return R.ok();
        } else {
            return R.error();
        }
    }

}
